@extends('admin::layouts.master')
@section('content')
    <div class="card" id="app">
        <div class="card-header">轮播图管理</div>
        <ul role="tablist" class="nav nav-tabs">
            <li class="nav-item"><a href="/slider/slider" class="nav-link">轮播图列表</a></li>
            <li class="nav-item"><a href="#" class="nav-link active">修改轮播图</a></li>
        </ul>
        <form action="/slider/slider/{{$slider['id']}}" method="post">
            <div class="card-body card-body-contrast">
                @csrf @method('PUT')
                <div class="form-group row">
    <label for="title" class="col-12 col-sm-3 col-form-label text-md-right">标题</label>
    <div class="col-12 col-md-9">
        <input id="title" name="title" type="text"
               value="{{ $slider['title']??old('title') }}"
               class="form-control form-control-sm form-control{{ $errors->has('title') ? ' is-invalid' : '' }}">
        @if ($errors->has('title'))
            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('title') }}</strong>
            </span>
        @endif
    </div>
</div>
<div class="form-group row">
    <label for="link" class="col-12 col-sm-3 col-form-label text-md-right">链接</label>
    <div class="col-12 col-md-9">
        <input id="link" name="link" type="text"
               value="{{ $slider['link']??old('link') }}"
               class="form-control form-control-sm form-control{{ $errors->has('link') ? ' is-invalid' : '' }}">
        @if ($errors->has('link'))
            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('link') }}</strong>
            </span>
        @endif
    </div>
</div>
<div class="form-group row">
    <label for="thumb" class="col-12 col-sm-3 col-form-label text-md-right">缩略图</label>
    <div class="col-sm-9">
        <div class="input-group mb-1">
            <input class="form-control  form-control-sm" name="thumb" readonly="" value="{{ $slider['thumb']??old('thumb') }}">
            <div class="input-group-append">
                <button onclick="upImagePc(this)" class="btn btn-secondary" type="button">单图上传</button>
            </div>
        </div>
        <div style="display: inline-block;position: relative;">
            <img src="{{$slider['thumb']??old('thumb')}}" class="img-responsive img-thumbnail" width="150">
            <em class="close" style="position: absolute;top: 3px;right: 8px;" title="删除这张图片"
                onclick="removeImg(this)">×</em>
        </div>
    </div>
    <script>
        require(['hdjs','bootstrap']);
        //上传图片
        function upImagePc() {
            require(['hdjs'], function (hdjs) {
                var options = {
                    multiple: false,//是否允许多图上传
                    //data是向后台服务器提交的POST数据
                    data: {name: '后盾人', year: 2099},
                };
                hdjs.image(function (images) {
                    //上传成功的图片，数组类型
                    $("[name='thumb']").val(images[0]);
                    $(".img-thumbnail").attr('src', images[0]);
                }, options)
            });
        }
        //移除图片
        function removeImg(obj) {
            $(obj).prev('img').attr('src', '{{asset ("image/nopic.jpg")}}');
            $(obj).parent().prev().find('input').val('');
        }
    </script>
</div>
<div class="form-group row">
    <label for="isshow" class="col-12 col-sm-3 col-form-label text-md-right" style="padding-top:initial;">显示</label>
    <div class="col-12 col-md-9">
                    <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio"
                           {{old('isshow',$slider['isshow'])=='1'?'checked':''}}
                           name="isshow" value="1"
                           id="isshow-1">
                    <label class="form-check-label" for="isshow-1">是</label>
           </div>            <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio"
                           {{old('isshow',$slider['isshow'])=='2'?'checked':''}}
                           name="isshow" value="2"
                           id="isshow-2">
                    <label class="form-check-label" for="isshow-2">否</label>
           </div>
        <br>
        @if ($errors->has('isshow'))
            <span class="text-danger">
                <strong>{{ $errors->first('isshow') }}</strong>
            </span>
        @endif
    </div>
</div>

            </div>
            <div class="card-footer text-muted">
                <button class="btn btn-primary offset-sm-2">保存更新</button>
            </div>
        </form>
    </div>
@endsection
